﻿using BBICMS.Model;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BBICMS.Repository.Configuration
{
    public class ProductPhotoMap : EntityTypeConfiguration<ProductPhoto>
    {
        public ProductPhotoMap()
        {
            this.HasKey(c => c.Id);

            this.Property(p => p.Id)
                .HasColumnName("Id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.ToTable("ProductPhotos");

        
            this.Property(p => p.Importance).IsRequired();
            this.Property(p => p.ProductId).IsRequired();

            this.Property(p => p.ImageUrl).HasMaxLength(150);
            this.Property(p => p.AddedDate).IsRequired().HasColumnType("datetime");
            this.Property(p => p.AddedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);

            this.HasRequired(p => p.Product)
            .WithMany(h=>h.ProductPhotos)
            .HasForeignKey(p => p.ProductId);  
        }
    }
}
